const config = {
  key: '2b127f4b8555dc40bf4069ca2f79f751',
  securityJsCode: '368305710dd3e93ac1330686ef31b2b7'
}

export default function MapLoader() {
  window._AMapSecurityConfig = {
    securityJsCode: config.securityJsCode
  }
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      resolve(window.AMap)
    } else {
      var script = document.createElement('script')
      script.type = 'text/javascript'
      script.async = true
      script.src = `https://webapi.amap.com/maps?v=1.4.15&key=${config.key}&callback=initAMap`
      script.onerror = reject
      document.head.appendChild(script)
    }
    window.initAMap = () => {
      // 'AMap.Geocoder',
      console.log('=====地图加载====', window.AMap)
      window.AMap.plugin( 'AMap.Geolocation', () => {
        resolve(window.AMap)
      })
    }
  })
}
